module ecs{
    export class Component implements IComparable<Component>{
        public _updateOrder: number = 0;
        public Entity: Entity;

        private _enabled: boolean = true;
        public get Enabled(){
            return this.Entity != null ? this.Entity.Enabled && this._enabled : this._enabled;
        }

        public set Enabled(value: boolean){
            this.SetEnabled(value);
        }

        public SetEnabled(isEnabled: boolean): Component{
            if (this._enabled != isEnabled){
                this._enabled = isEnabled;

                if (this._enabled)
                    this.OnEnabled();
                else
                    this.OnDisabled();
            }

            return this;
        }

        /** 在为该Component分配了其Entity但尚未将其添加到该实体的活动Components列表中时调用 */
        public Initialize(){};

        public OnEnabled(){}

        public OnDisabled(){}

        public OnEntityTransformChanged(comp: transform.Component){}

        CompareTo(other: Component): number {
            return this._updateOrder.CompareTo(other._updateOrder);
        }
    }
}